/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package commonUtils;

import com.nct.framework.util.ConvertUtils;
import com.nct.framework.util.DateTimeUtils;
import extentEntity.TwitterPostEnt;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author liempt
 */
public class FunctionUtils {
    
    public static String DateToStringView(long date) {
        SimpleDateFormat ad = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        return ad.format(date);
    }
    
    public static String DateToDirView() {
        Date inDate = DateTimeUtils.getNow();
        String sYear = ConvertUtils.toString(inDate.getYear()+1900);
        int iNumber = inDate.getMonth()+1;
        String sMonth = iNumber>=10 ? ConvertUtils.toString(iNumber) : "0"+ConvertUtils.toString(iNumber);
        iNumber = inDate.getDate();        
        String sDay = iNumber>=10 ? ConvertUtils.toString(iNumber) : "0"+ConvertUtils.toString(iNumber);

        return ConvertUtils.toString(sYear + sMonth + sDay);
    }
    
    public static String ClearText(String inputText) {
        String regexSymbol = "[\\/\\[\\]|+@~!*@#$%^&?{}().,:;\\-=_\'\"<>]";
        
        return inputText.replaceAll(regexSymbol, "");
    }
    
    public static String ClearStopWord(String inputText) {
        String regexSymbol = "[\\/\\[\\]|+@~!*@#$%^&?{}().,:;\\-=_\'\"<>]";
        //Doc File StopWord roi xoa
        return inputText.replaceAll(regexSymbol, "");
    }
    
    public static TwitterPostEnt ConvertContentToMessage1(TwitterPostEnt twitterPostEnt) {
//        String regex = "<\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]>";
        String regex = "http://\\S+\\s*";
        
        String newContent = twitterPostEnt.TweetContent;
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(twitterPostEnt.TweetContent);
        String linkURL = "";
        if (matcher.find()) {
            String tmp = matcher.group();
            if(!tmp.isEmpty()){
                newContent = newContent.replaceAll(tmp, "");
                linkURL += "," + tmp;
            }
        }
        
        twitterPostEnt.LinkUrl = linkURL.isEmpty() ? "" : linkURL.substring(1);
        twitterPostEnt.Message1 = ClearText(newContent);
        twitterPostEnt.Status = TwitterPostEnt.STATUS.ToMsg1;
        
        return twitterPostEnt;
    }
}
